package org.huang.api;

import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.huang.util.User;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpStatus;
import org.springframework.http.HttpStatusCode;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author hdu_huang
 * @since 2024/1/10 17:19
 */

@RestController
@Slf4j
public class DemoController {
    @GetMapping("loader")
    public HttpEntity<Object> getClassLoader(HttpServletRequest request) {

        ClassLoader classLoader = this.getClass().getClassLoader();
        ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
        log.error("User classLoader : {}, parent : {}", classLoader, classLoader.getParent());
        log.error("Thread classLoader : {}, parent : {}", contextClassLoader, contextClassLoader.getParent());

        return new HttpEntity<>(classLoader.toString());
    }

    //不再支持user/(最后以/尾的路径)
    @GetMapping("user")
    public HttpEntity<Object> getUser(Integer id) {

        var user = new User(30, "huang");

        return new HttpEntity<>(user);
    }

    @GetMapping("test")
    public HttpEntity<User> test() {

        var user = new User(30, "hec");

       var responseEntity = ResponseEntity.status(HttpStatus.BAD_REQUEST).body(user);
        responseEntity.getHeaders().size();

        return responseEntity;
    }
}
